/*****
 * 
 * DeckBuilderForm.java
 * 
 * Copyright (c) 2011 Rocco Nicosia / TwoBit MTG Toolkit. 
 * 
 * License information: http://www.gnu.org/licenses/agpl-3.0-standalone.html
 * 
 *****/
package twobitclient;

import javax.swing.*;
import twobitclient.twobit.*;
import twobitclient.utils.*;
import java.util.ArrayList;

/*****
 * 
 * Creates / maintains basic window functions in deck builder mode. 
 * (populateFullCardList() only exists within this class for testing 
 * purposes. Will be moved / rewritten for the final program. This file is
 * also considered the entry point for the program. This will also presumably
 * be changed in favor of a main welcome / menu screen.)
 * 
 *****/
public class DeckBuilderForm extends javax.swing.JFrame {

    private static ExpansionListParser listParser;
    private static DefaultListModel model = new DefaultListModel();
    private static ArrayList<MagicCard> m_cardArray;
    private static String fileName = System.getProperty("user.dir") + 
            "\\src\\twobitclient\\resources\\cardsets\\Core2012.xml";
    
    /** Creates new form DeckBuilderForm */
    public DeckBuilderForm() {
        initComponents();
        populateFullCardList();
    }

    private void populateFullCardList()
    {
        listParser = new ExpansionListParser();
        m_cardArray = listParser.parseDocument(fileName);
        
        for (MagicCard i : m_cardArray)
        {
            int pos = JListFullCardList.getModel().getSize();
            model.add(pos, i.toString());
        }
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        SearchField = new javax.swing.JTextField();
        CardDataViewport = new javax.swing.JPanel();
        FullCardListScrollPane = new javax.swing.JScrollPane();
        JListFullCardList = new javax.swing.JList(model);
        DeckListScrollPane = new javax.swing.JScrollPane();
        JListDeckList = new javax.swing.JList();
        AddFourButton = new javax.swing.JButton();
        AddOneButton = new javax.swing.JButton();
        RemoveAllButton = new javax.swing.JButton();
        RemoveOneButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("TwoBit Deck Builder");

        CardDataViewport.setBackground(new java.awt.Color(153, 153, 153));

        javax.swing.GroupLayout CardDataViewportLayout = new javax.swing.GroupLayout(CardDataViewport);
        CardDataViewport.setLayout(CardDataViewportLayout);
        CardDataViewportLayout.setHorizontalGroup(
            CardDataViewportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 399, Short.MAX_VALUE)
        );
        CardDataViewportLayout.setVerticalGroup(
            CardDataViewportLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 837, Short.MAX_VALUE)
        );

        FullCardListScrollPane.setViewportView(JListFullCardList);

        DeckListScrollPane.setViewportView(JListDeckList);

        AddFourButton.setText(">> ADD 4 >>");

        AddOneButton.setText(">> ADD 1 >>");

        RemoveAllButton.setText("REMOVE ALL");

        RemoveOneButton.setText("REMOVE 1");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(SearchField)
                    .addComponent(FullCardListScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 331, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(RemoveAllButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(RemoveOneButton, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(AddFourButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(AddOneButton, javax.swing.GroupLayout.DEFAULT_SIZE, 104, Short.MAX_VALUE))
                .addGap(18, 18, 18)
                .addComponent(DeckListScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 331, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(10, 10, 10)
                .addComponent(CardDataViewport, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(CardDataViewport, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(SearchField, javax.swing.GroupLayout.PREFERRED_SIZE, 32, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(DeckListScrollPane, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(FullCardListScrollPane, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 652, Short.MAX_VALUE))))
                        .addContainerGap())
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(AddOneButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(AddFourButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(12, 12, 12)
                        .addComponent(RemoveOneButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(RemoveAllButton, javax.swing.GroupLayout.PREFERRED_SIZE, 87, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(145, 145, 145))))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton AddFourButton;
    private javax.swing.JButton AddOneButton;
    private javax.swing.JPanel CardDataViewport;
    private javax.swing.JScrollPane DeckListScrollPane;
    private javax.swing.JScrollPane FullCardListScrollPane;
    private javax.swing.JList JListDeckList;
    private javax.swing.JList JListFullCardList;
    private javax.swing.JButton RemoveAllButton;
    private javax.swing.JButton RemoveOneButton;
    private javax.swing.JTextField SearchField;
    // End of variables declaration//GEN-END:variables

    public static void main(String args[]) {
        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new DeckBuilderForm().setVisible(true);
            }
        });
    }    

}
